<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="/favicon.ico">
    <title>朋友圈</title>
    <!-- Bootstrap core CSS -->
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <!-- Custom styles for this template -->
    <style>
        body{

            background-image: url("/avatar/homebg.jpg");
        }
        .fabukuang{
            margin-top: 90px;
            margin-bottom: 20px;
        }
        .fabukuang2{
            margin-top: 50px;
            margin-bottom: 20px;
        }
        .fabukuang3{
            margin-left: -60px;
            margin-top: 80px;
            margin-bottom: 20px;
        }
        #inputarea{

            height: 100px;
            width:100%;
        }
        .btn{
            float: right;
            margin-top: 7px;
        }
        h4{
            margin-top: -20px;
        }
        .content{
            margin-bottom: 10px;
            border-radius:5px;
        }
        .icon{
            margin-top: 10px;
            margin-left: 10px;
            height: 35px;
            width:35px;
            float: left;
        }
        .content p{
            float: left;
            margin-top: 17px;
            margin-left: 10px;
        }
    </style>
</head>

<body>

<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top" style="background: #91C4C7">

    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">朋友圈</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li class="active"><a href="#">全部动态</a></li>
                <%
                if(login){
                %>
                <li><a href="/myfabu">我的发布</a></li>
                <%}%>

            </ul>
            <%
                if(!login){
            %>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="/regist">注册</a></li>
                <li><a href="/login">登录</a></li>
            </ul>
            <%
                }else{
            %>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#"> 欢迎您! <%= username %></a></li>
                <li>
                    <a href="#">
                        <img id="icon" src="/avatar/<%=username%>.jpg" style="width: 25px;height: 25px;">
                    </a>
                </li>
                <li><a href="/setavatar">修改头像</a></li>
            </ul>
            <%
                }
            %>

        </div>
    </div>
</nav>

<div class="container">

    <!-- Main component for a primary marketing message or call to action -->
    <%
    if(login){
    %>

    <div class="row">
        <div class="col-md-10 fabukuang">
            <h4 style="color:greenyellow">有什么新鲜事告诉大家？</h4>
            <textarea name="" id="inputarea" cols="30" rows="10" placeholder="输入你想写的内容吧"></textarea>
            <button type="button" id="fabu" class="btn btn-danger">发送</button>
        </div>
    </div>

    <%}else{%>

    <div class="row">

        <div class="col-md-5 col-offset-1 fabukuang2">
            <h3>欢迎来到朋友圈</h3>
            <img style="width: 60%;height: 200px" src="/avatar/welcome2.png" alt="">
        </div>
        <div class="col-md-5 fabukuang3">
            <h2></h2>
            <form>
                <div class="form-group">
                    <label for="exampleInputEmail1">用户名</label>
                    <input type="text" class="form-control" id="username" placeholder="用户名">
                </div>
                <div class="form-group">
                    <label for="exampleInputPassword1">密码</label>
                    <input type="password" class="form-control" id="password" placeholder="密码">
                </div>

                <button type="button" id="submit" class="btn btn-default">登录</button>
            </form>
            <div class="alert alert-danger" style="display: none" role="alert">密码错误</div>
        </div>
    </div>

    <%}%>

    <div class="row" id="app">
        <div style="background:white;height: 150px;" class="col-md-10 content" v-for="item in result">
            <div style="height: 60px">
                <img :src='item.avatar' class="icon" alt="">
                <p>{{item.username}}</p>
                <img src='/avatar/renzheng.png' style="margin-top: 14px;margin-left: 10px" alt="">
            </div>
            <div style="margin-left: 45px;margin-top: -30px">
                <p>{{item.content}}</p>
            </div>
        </div>

    </div>
</div> <!-- /container -->


<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script  src="/js/jquery-1.11.3.min.js"></script>
<script  src="/js/vue.min.js"></script>
<script  src="/js/bootstrap.min.js"></script>
<script type="text/javascript">



        $('#fabu').click(function () {
            if($('#inputarea').val()){
                $.post("/dopostcontent",{
                    'content':$('#inputarea').val()
                },function(status){
                    if(status == '1'){
                        //发布成功
                        window.location = '/';
                    }else if(status == '-3'){
                        alert('服务器错误');
                    }
                });
            }else{
                alert('请输入要发布的内容');
            }

        });




    function getContentList() {
        $.get("/contentlist", function(result){
            new Vue({
                el: '#app',
                data: {
                    result:result.result
                }
            });
        });
    }
    getContentList();
    $("input").focus(function(){
        $('.alert').fadeOut();
    });
    $('#submit').click(function () {
        if($('#username').val() && $('#password').val()){
            $.post("/dologin",{
                'username':$('#username').val(),
                'password':$('#password').val()

            },function(status){

                if(status == '1'){
                    //登录成功
                    window.location = '/';
                }else if(status == '-1'){
                    $('.alert').fadeIn();
                    $('.alert').html('没有该用户');
                }else if(status == '-3'){
                    alert('服务器错误');
                }else{

                    $('.alert').fadeIn();

                    $('.alert').html('密码错误');
                }

            });
        }else{
            $('.alert').fadeIn();

            $('.alert').html('密码错误');
        }


    })

</script>
</body>
</html>
